--- 战策十二·见缝插针
local policy12 = fk.CreateSkill {
    name = "getchance_insmall",
    tags = { Skill.Compulsory },
    dynamic_name = function (self, player, lang)
      return player == Self and self.name or "unknownpolicy"
    end,
    dynamic_desc = function (self, player, lang)
      return player == Self and self.name or "unknownpolicy"
    end,
}

local HG = require "packages/new_heg_diy_my/util"

Fk:loadTranslationTable {
    ["@[getchance_insmall_mark]"] = "见缝插针",
    ["getchance_insmall_ask"] = "战策-见缝插针：你可以弃置一张牌，成为此牌的额外目标",
}


policy12:addEffect(fk.TargetSpecifying, {
    can_trigger = function(self, event, target, player, data)
        local mark_name = "@[private]" .. policy12.name .. "_mark"
        return player:getMark(mark_name) ~= 0 and target ~= player and player ~= data.to and data.card.trueName ~= "threaten_emperor" and
            (data.card:isCommonTrick() or data.card.type == Card.TypeBasic) and data:isOnlyTarget(data.to) and
            not player:isNude()-- and table.contains(data:getExtraTargets({bypass_distances = true}), player)
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local cards = room:askToDiscard(player, {
            min_num = 1,
            max_num = 1,
            include_equip = true,
            skill_name = "unknownpolicy",
            prompt = "getchance_insmall_ask",
            skip = true,
            cancelable = true,
        })
        if #cards > 0 then
            event:setCostData(self, { cards = cards })
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local mark_name = "@[private]" .. policy12.name .. "_mark"
        room:throwCard(event:getCostData(self).cards[1], policy12.name, player, player)
        data:addTarget(player, nil)
        room:setPlayerMark(player, mark_name, 0)
        room:handleAddLoseSkills(player, "-getchance_insmall", nil, false)
        room.logic:trigger(HG.HegLosePolicy, player, { player, policy12.name })
    end,
})

return policy12
